package com.dule.Medic.pages;

import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.dule.Medic.model.Doctor;
import com.dule.Medic.model.MedEntry;
import com.dule.Medic.model.Patient;
import com.dule.Medic.model.Prescription;
import com.dule.Medic.service.MedEntryService;

public class ChangePrescriptionData 
{
	@SuppressWarnings("unused")
	@SessionState      
	@Property    
	private Doctor doctor;     
	private boolean doctorExists;    
	
	@SuppressWarnings("unused")
	@SessionState
	@Property
	private Patient patient;
	private boolean patientExists;
	
	@SessionState
	@Property
	private MedEntry medentry;
	private boolean medentryExists;
	
	@SessionState
	@Property
	private Prescription prescription;
	
	@Inject
	private MedEntryService medentryservice; 
	
	public Object onActivate()
	{   
		if(doctorExists)
		{
			if(patientExists)
			{
				if(medentryExists)
				{
					return null;
				}
				else
				{
					return ExaminePatient.class;
				}
			}
			else
			{
				return Index.class;
			}
		}        
		return FirstPage.class;   
	}
	
	@OnEvent(component="prescriptionform")  
	public Object OnPrescriptionForm()
	{   
		medentry.UpdatePrescription(prescription);
		medentryservice.update(medentry);
		return ChangeMedEntryData.class;  
	} 
}
